const F = t;
function S() {
    const H = [
        'logicalOperator',
        'enterDmlStatement',
        'enterLimitClause',
        'toLowerCase',
        'getText',
        'parse',
        'indexOf',
        'exitLogicalExpression',
        'field',
        '721890KnOKgq',
        '10465588VQNIRA',
        '8296000gqCwYH',
        'fieldNames',
        'limitNum',
        '190ELBtcR',
        'whereCondStr',
        '6764GWhYWg',
        'parseObj',
        '34149sHkCTe',
        'substring',
        'logicalExpressionStopIdx',
        '12PqkCZX',
        'distinct',
        'expressionFlag',
        'sql',
        '6404960urVXdv',
        'logicalOperators',
        'log',
        'stop',
        'enterLogicalExpression',
        'comparisonOperator',
        'join',
        'keys',
        'isDistinct',
        'forEach',
        'logicalExpressionStartIdx',
        'length',
        '19892538YbUbsv',
        'where',
        'SelectElements',
        'enterComparisonOperator',
        'enterSelectElements',
        'collection',
        'add',
        'start',
        'opName',
        'querySpecification',
        'push',
        'includes',
        'comparisonOperators',
        'whereConfig',
        'logicalExpression',
        'findIndex',
        'AND',
        'limit',
        'replace'
    ];
    S = function () {
        return H;
    };
    return S();
}
(function (L, Z) {
    const P = t;
    const R = L();
    while (!![]) {
        try {
            const w = parseInt(P(0xa4)) / (-0x1 * -0x13fa + -0x43d + -0x4c * 0x35) * (-parseInt(P(0xa2)) / (0x24c4 + -0x622 + -0x1ea0)) + -parseInt(P(0x6e)) / (0xb * -0x373 + 0x1a * -0x7f + 0x32da) * (parseInt(P(0x71)) / (0x16f8 * -0x1 + -0xa * -0x293 + -0x161 * 0x2)) + -parseInt(P(0x75)) / (0xe11 + 0x1a4f + -0x285b) + parseInt(P(0x9d)) / (-0x32e + 0xe * -0x283 + 0x265e) + parseInt(P(0x9e)) / (0x1 * -0x203e + 0xa29 + 0x161c) + -parseInt(P(0x9f)) / (-0xe0b * -0x1 + -0x168 * 0x17 + 0x1255) + parseInt(P(0x81)) / (0x150c + 0x12af * -0x1 + -0x254);
            if (w === Z) {
                break;
            } else {
                R['push'](R['shift']());
            }
        } catch (v) {
            R['push'](R['shift']());
        }
    }
}(S, 0x10fa40 + -0x1 * -0x2a6d + 0x476bd * -0x1));
const {GenericSQL, SqlParserListener} = require('dt-sql-parser');
const parser = new GenericSQL();
const sqlOpMapToJql = {
    'SELECT': 'get',
    'INSERT': F(0x87),
    'UPDATE': 'update',
    'DELETE': 'delete'
};
const sqlOps = Object[F(0x7c)](sqlOpMapToJql);
const jqlOps = Object['values'](sqlOpMapToJql);
function t(L, Z) {
    const R = S();
    t = function (w, v) {
        w = w - (0x81 * -0x1 + 0x182f + -0x1740);
        let k = R[w];
        return k;
    };
    return t(L, Z);
}
const getWhereCondStr = L => {
    const A = F;
    let Z = null;
    if (L[A(0x7f)] === null) {
        Z = '';
    } else {
        let R = L[A(0x73)][A(0x93)](A(0x91), '&&');
        R = L['expressionFlag'][A(0x93)]('OR', '||');
        Z = R;
        if (L[A(0x8d)]['includes']('=')) {
            const w = R['split']('');
            w[A(0x7e)]((v, k) => {
                if (v === '=' && [
                        '>',
                        '<',
                        '!'
                    ]['includes'](w[k - (0x233 * 0x10 + 0x1652 + -0x3981)])) {
                    w[k] = '==';
                }
            });
            Z = w[A(0x7b)]('');
        }
    }
    return Z;
};
const _whereConfig = Symbol(F(0x8e));
class MyListener extends SqlParserListener {
    constructor(L, Z) {
        const y = F;
        super();
        this[y(0x74)] = Z;
        this[y(0xa5)] = L;
        this[_whereConfig] = {
            'expressionFlag': null,
            'logicalExpressionStartIdx': null,
            'logicalExpressionStopIdx': null,
            'comparisonOperators': [],
            'logicalOperators': []
        };
    }
    ['enterTableName'](L) {
        const p = F;
        let Z = this[p(0x74)]['substring'](L[p(0x88)][p(0x88)], L['stop']['stop'] + (0x169d + -0xb6 + -0x15e6))[p(0x93)](/\"|\'/g, '');
        if (!this[p(0xa5)]['collectionNames'][p(0x8c)](Z)) {
            this[p(0xa5)]['collectionNames']['push'](Z);
        }
    }
    [F(0x85)](L) {
        const Y = F;
        let Z = this[Y(0x74)]['substring'](L[Y(0x88)][Y(0x88)], L['stop'][Y(0x78)] + (0x252f + -0x731 * 0x1 + -0x1dfd));
        console[Y(0x77)](Y(0x83), Z);
        this[Y(0xa5)][Y(0xa0)] = Z['split'](',');
    }
    [F(0x95)](L) {
        const Q = F;
        let Z = L[Q(0x98)]()[Q(0x97)]();
        const R = sqlOps[Q(0x90)](w => Z['indexOf'](w[Q(0x97)]()) === -0x4 * -0x3c1 + 0x1edf * 0x1 + -0x2de3);
        if (R !== -(-0x62 * 0x50 + 0x1347 + 0xb5a)) {
            this[Q(0xa5)][Q(0x89)] = jqlOps[R];
        }
        if (Z[Q(0x9a)](Q(0x72)) !== -(-0x2560 + 0xbfd + 0x1964)) {
            this[Q(0xa5)][Q(0x7d)] = !![];
        }
    }
    ['enterQuerySpecification'](L) {
        const r = F;
        let Z = L[r(0x98)]();
        console[r(0x77)](r(0x8a), Z);
        this['parseObj'][r(0x8a)] = Z;
    }
    [F(0x79)](L) {
        const q = F;
        let Z = this[q(0x74)][q(0x6f)](L[q(0x88)][q(0x88)], L[q(0x78)][q(0x78)] + (-0x1a59 + 0xfa + -0x1 * -0x1960));
        console['log'](q(0x8f), Z);
        this[_whereConfig]['expressionFlag'] = Z;
        this[_whereConfig][q(0x7f)] = L['start'][q(0x88)];
        this[_whereConfig][q(0x70)] = L[q(0x78)][q(0x78)];
    }
    [F(0x84)](L) {
        const e = F;
        let Z = this[e(0x74)][e(0x6f)](L[e(0x88)][e(0x88)], L[e(0x78)][e(0x78)] + (-0x25ef + -0x67 * -0x3b + -0x5 * -0x2d7));
        console['log'](e(0x7a), Z);
        this[_whereConfig][e(0x8d)]['push']({
            'flag': Z,
            'startIdx': L[e(0x88)]['start'],
            'stopIdx': L[e(0x78)][e(0x78)]
        });
        this[e(0xa5)][e(0x7a)] = Z;
    }
    ['enterLogicalOperator'](L) {
        const B = F;
        let Z = this[B(0x74)][B(0x6f)](L['start']['start'], L[B(0x78)]['stop'] + (0xd86 * 0x1 + -0xb1d + -0x268));
        console[B(0x77)](B(0x94), Z);
        this[_whereConfig][B(0x76)][B(0x8b)]({
            'flag': Z,
            'startIdx': L['start']['start'],
            'stopIdx': L[B(0x78)][B(0x78)]
        });
        this['parseObj'][B(0x94)] = Z;
    }
    [F(0x9b)](L) {
        const I = F;
        let Z = this[I(0x74)][I(0x6f)](L[I(0x88)][I(0x88)], L[I(0x78)][I(0x78)] + (-0x15b * -0xc + -0xc04 * 0x2 + 0x75 * 0x11));
        this[I(0xa5)][I(0xa3)] = getWhereCondStr(this[_whereConfig]);
    }
    [F(0x96)](L) {
        const C = F;
        let Z = L[C(0x98)]()['toLowerCase']();
        this[C(0xa5)][C(0xa1)] = +Z['replace'](C(0x92), '');
    }
    ['enterOrderByClause'](L) {
    }
}
const isValidSql = L => {
    const W = F;
    const Z = parser['validate'](L);
    return Z[W(0x80)] === 0x12 * -0x112 + 0x35e + 0xfe6;
};
const parseSql = L => {
    const j = F;
    const Z = parser[j(0x99)](L);
    const R = {
        'collectionNames': [],
        'fieldNames': [],
        'whereCondStr': null,
        'isDistinct': ![],
        'limitNum': null,
        'opName': null,
        'opCond': {}
    };
    const w = new MyListener(R, L);
    parser['listen'](w, Z);
    return w[j(0xa5)];
};
const getJqlFromObj = async (L, Z) => {
    const o = F;
    console[o(0x77)](L, L[o(0xa0)][o(0x7b)](','));
    if (L['collectionNames'][o(0x80)] !== 0xb5c + 0x1 * 0x1e6d + -0x29c8) {
        return null;
    }
    let R = Z[o(0x86)](L['collectionNames'][-0x211c + 0x1459 + -0x21 * -0x63]);
    if (L[o(0xa0)]['length'] > 0x26dd * 0x1 + -0x6d8 + -0x2005) {
        R = R[o(0x9c)](L['fieldNames'][o(0x7b)](','));
    }
    if (L[o(0x7d)] && L[o(0xa0)][o(0x80)] > 0x1127 * -0x1 + -0x1 * -0x199d + -0x2 * 0x43b) {
        R = R[o(0x72)]();
    }
    if (L['whereCondStr']) {
        R = R[o(0x82)](L[o(0xa3)]);
    }
    if (L[o(0xa1)] > -0xe6e + 0x1 * -0xc6d + -0x37 * -0x7d) {
        R = R[o(0x92)](L[o(0xa1)]);
    }
    return R[L[o(0x89)]](L['opCond']);
};
const transSqlToJqlPromise = async (L, Z) => {
    if (!isValidSql(L)) {
        return null;
    } else {
        const R = parseSql(L);
        return getJqlFromObj(R, Z);
    }
};
module['exports'] = function (L) {
    return { 'transSqlToJqlPromise': transSqlToJqlPromise };
};